from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.


class User(AbstractUser):
    first_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200)
    email = models.EmailField(unique=True)
    password = models.CharField(max_length=200)
    isAdmin = models.BooleanField(default=False)

    tours = models.ManyToManyField('Tour', blank=True, related_name='users', through='UserTour')

    def get_full_name(self):
        return f"{self.first_name} {self.last_name}"


class Tour(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField()
    seats = models.IntegerField()
    price = models.IntegerField()
    isActive = models.BooleanField(default=True)
    arrivalDate = models.DateTimeField(default=None, blank=False, null=False)
    departureDate = models.DateTimeField(default=None, blank=False, null=False)
    image = models.ImageField(upload_to='images/tours/')


class UserTour(models.Model):
    user = models.ForeignKey('User', on_delete=models.CASCADE)
    tour = models.ForeignKey('Tour', on_delete=models.CASCADE)
    isPaid = models.BooleanField(default=False)

